#include <iostream>
#include <vector>
using namespace std;

int partition(vector<int>& nums, int left, int right) {
    int pivot = nums[right];
    int index = left - 1;

    for (int i = left; i < right; i++) {
        if (nums[i] < pivot) {
            index++;
            swap(nums[index], nums[i]);
        }
    }
    swap(nums[index + 1], nums[right]);
    return index + 1;
}

void quick_sort(vector<int>& nums, int left, int right) {
    if (left >= right) {
        return;
    }

    int index = partition(nums, left, right);
    quick_sort(nums, left, index - 1);
    quick_sort(nums, index + 1, right);
}

int main() {
    vector<int> nums = {1, 8, 3, 5, 6, 7, 2, 4};
    int n = nums.size();
    quick_sort(nums, 0, n - 1);
    
    for (int n : nums) {
        cout << n << " ";
    }
    return 0;
}